import { ref } from "vue";
import { defineStore } from "pinia";
import request from "@/utils/axios";
export const useDemoStore = defineStore("back", {
    state: () => {
        return {
            // 网盘返回状态存储
            netdiskObj: {
                currentTypeId: {} as any,
                breadCrumb: [] as any,
                status: {} as any,
                tabVal: "",
                goStatus: 0,
                backStatus: 10,
            },
            // 媒资列表筛选条件
            filterObj:{}  as any,
            timeId:'全部' as string,
            dateVal:[]  as any,

            // 相似
            similarityObj: {
                title: "" as any,
                id: "" as any,
            },
            // 相似
            searchObj: {
                text: "" as string,
            },
            currentRouteObj: {},
        };
    },
    getters: {},
    actions: {
        // 调接口获取面包屑存到store里面
         setBreadCrumbById () {
            if(!this.netdiskObj.currentTypeId.media_resource_id || this.netdiskObj.currentTypeId.media_resource_id=='0'){
                this.netdiskObj.breadCrumb = [{ title: '全部', file_id: null }]
                return Promise.resolve("all")
            }
            return request({
                url: `/mediaresource-manage-service/medias/${this.netdiskObj.currentTypeId.media_resource_id}/path`,
                method: "get",
            }).then((res) => {
                if (res.data.status_code == 1) {
                    this.netdiskObj.breadCrumb = [{ title: '全部', file_id: null }]
                    const data = res.data.result.data
                    if( data && data.namespath && data.idspath){
                        let arrNames =data.namespath.split(/\//).filter((v:any)=> v);
                        let arrIds =data.idspath.split(/\//).filter((v:any)=> v);
                        arrNames.forEach((v:any,i:number)=>{
                            if(v!=="root"){
                                // 全部上面已经单独处理了
                                this.netdiskObj.breadCrumb.push({
                                    title:v,
                                    id:arrIds[i] || '',
                                    media_resource_id:arrIds[i] || '',
                                    main_type:7
                                })
                            }
                        })
                    }
                    
                } 
            });

         }
    },
});
